﻿@model Models.Notice
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>@ViewData["Title"]</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <environment include="Development">
        <link rel="stylesheet" href="~/layer/css/layui.css" media="all" />
        <link rel="stylesheet" href="~/layer/css/admin.css" media="all" />
    </environment>
    <environment exclude="Development">
        <link rel="stylesheet" href="~/layer/css/layui.css" asp-append-version="true" media="all" />
        <link rel="stylesheet" href="~/layer/css/admin.css" asp-append-version="true" media="all" />
    </environment>
</head>
<body id="iosiframe">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">@ViewData["Title"]</div>
                    <form class="layui-form" action="" lay-filter="component-form-element">
                        <div class="layui-card-body layui-row layui-col-space10">
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <label class="layui-form-label">@((Code.NoticeType)ViewData["type"] == Code.NoticeType.购买协议 ? "甲方" : "标题")</label>
                                    <div class="layui-input-block">
                                        <input type="text" maxlength="20" asp-for="Name" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                                        @if (Model.Id > 0) {
                                            <input type="hidden" asp-for="Id" />
                                            <input type="hidden" asp-for="NoticeType" />
                                            <input type="hidden" asp-for="CreateTime" />
                                        }
                                    </div>
                                </div>
                            </div>

                            @if ((Code.NoticeType)ViewData["type"] != Code.NoticeType.购买协议) {
                                <div class="layui-form-item">
                                    <div class="layui-col-lg6">
                                        <label class="layui-form-label">封面图</label>
                                        <div class="layui-upload">
                                            <button type="button" class="layui-btn" id="uploadimg">上传图片</button><input class="layui-upload-file" type="file" accept="undefined">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item" id="layui_img" style="display:none;">
                                    <div class="layui-col-lg6">
                                        <label class="layui-form-label"></label>
                                        <div class="layui-upload">
                                            <input type="hidden" asp-for="ImgUrl" />
                                            <img class="layui-upload-img" width="200" height="200" id="test-upload-normal-img">
                                        </div>
                                    </div>
                                </div>
                            }
                            <div class="layui-form-item">
                                <label class="layui-form-label">@((Code.NoticeType)ViewData["type"] == Code.NoticeType.购买协议 ? "协议内容" : "内容")</label>
                                <div class="layui-input-block">
                                    <textarea asp-for="Content" style="display: none;" id="Content" placeholder="" class="layui-textarea"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="component-form-element">立即提交</button>
                                    @if ((Code.NoticeType)ViewData["type"] != Code.NoticeType.购买协议) {
                                        <a class="layui-btn  layui-btn-primary" lay-filter="component-form-element" href="@Url.Action("list", "notice")">返回</a>
                                    }
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script src="~/layer/layui.js"></script>
    <script>
        layui.config({
            base: '../../layer/' //静态资源所在路径
        }).extend({
            index: 'index' //主入口模块
        }).use(['form', 'upload', 'layedit'], function () {
            var $ = layui.$
                , form = layui.form
                , router = layui.router()
                , search = router.search
                , upload = layui.upload
                , layedit = layui.layedit;

            var ua = navigator.userAgent.toLowerCase();
            var screenwidth = window.screen.width;
            if (!/iphone|ipad|ipod/.test(ua)) {
                $("#iosiframe").attr("scrolling", "auto");
            } else {
                $('#iosiframe').width(screenwidth + 'px');
            }

            if ($('#ImgUrl')) {
                var src = $('#ImgUrl').val();

                if (src && src.length > 0) {
                    $('#test-upload-normal-img').attr('src', src);
                    $('#layui_img').show();
                }
            }

            var index = layedit.build('Content', {
                tool: [
                    'strong' //加粗
                    , 'italic' //斜体
                    , 'underline' //下划线
                    , 'del' //删除线

                    , '|' //分割线

                    , 'left' //左对齐
                    , 'center' //居中对齐
                    , 'right' //右对齐
                    , 'link' //超链接
                    , 'unlink' //清除链接
                    , 'image' //插入图片
                ],
                uploadImage: { url:'@Url.Action("filesave","api")' }
            });

            var uploadInst = upload.render({
                elem: '#uploadimg'
                , url: '@Url.Action("filesave", "api")'
                , accept: 'images'
                , size: 2048
                , done: function (res, index, upload) {
                    if (res.code == 0) {
                        $('#test-upload-normal-img').attr('src', res.data.src);
                        $('#layui_img').show()
                    } else {
                        alert(res.msg);
                    }
                }
            });



            form.render(null, 'component-form-element');

            //提交
            form.on('submit(component-form-element)', function (data) {
                //layedit.sync(index);

                if ($('#test-upload-normal-img')) {
                    var src = $('#test-upload-normal-img').attr('src');
                    if (src && src.length > 0) {
                        data.field.ImgUrl = src;
                    }
                }
                data.field.Content = layedit.getContent(index);
                //JSON.stringify(data.field)

                $.ajax({
                    url: '@Url.Action("savenotice","api")',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(data.field),
                    type:'post'
                }).fail(function (jqXHR, textStatus, errorThrown) {
                    alert(errorThrown, { icon: 2, title: textStatus });
                }).done(function (res) {
                    layer.msg(res.message, { offset: '15px', icon: (res.code == 0 ? 1 : 2), time: 1000 });
                });
                return false;
            });


        });

    </script>

</body>
</html>

